package com.zoffy.ybuhelper.fragment;

import android.content.Context;
import android.content.SharedPreferences;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import com.zoffy.ybuhelper.R;


public class GPTLoginFragment extends AbstractLoginFragment{
    /**
     * editText1 为AppId输入框
     * editText2 为ApiKey输入框
     * editText3 为ApiSecret输入框
     */

    @Override
    protected void layoutInit() {
        textView1.setText(R.string.app_id);
        textView2.setText(R.string.api_key);
        textView3.setText(R.string.api_secret);
        editText1.setHint("请输入AppId");
        editText1.setInputType(EditorInfo.TYPE_CLASS_TEXT);
        editText2.setHint("请输入ApiKey");
        editText2.setInputType(EditorInfo.TYPE_CLASS_TEXT);
        editText3.setHint("请输入ApiSecret");
        editText3.setInputType(EditorInfo.TYPE_CLASS_TEXT);

    }

    @Override
    protected void listenerInit() {
        saveAcountButton.setOnClickListener(v-> {
                String appId=editText1.getText().toString();
                String apiKey=editText2.getText().toString();
                String apiSecret=editText3.getText().toString();
                SharedPreferences preferences=  getActivity().getSharedPreferences("user_data", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor= preferences.edit();
                editor.putString("appId",appId);
                editor.putString("apiKey",apiKey);
                editor.putString("apiSecret",apiSecret);
                editor.commit();
                getParentFragmentManager().beginTransaction().remove(this).commit();

        });

    }
}
